package com.xd.cloud.dao.vehicle;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xd.cloud.dao.BaseDao;
import com.xd.cloud.dao.Page;
import com.xd.cloud.entity.vehicle.VehicleInfo;

/**
 * @author wangtao
 * @class_name VehicleInfoDao
 * @description VehicleInfo持久层
 * @create 2017/12/6
 */
@Repository
public class VehicleInfoDao  extends BaseDao<VehicleInfo> {

//	public Page getAll(int pageNo, int pageSize) {
//		String hql = "from VehicleInfo";
//		return pagedQuery(hql, pageNo, pageSize);
//	}
	
	public Page getAll(int pageNo, int pageSize) {
		String sql = "select a.id,a.vehid,a.platetype,a.vehcolor,b.id as orgid,b.name as orgname,a.devicecode,a.status from tb_vehicle as a left join sys_company as b on a.companyid = b.id order by a.createtime desc";
		return pagedSqlQuery(sql, pageNo, pageSize);
	}
	
	public VehicleInfo getByVehid(String vehid)
	{
		String hql = "from VehicleInfo where vehid=?";
		return get(hql, new Object[] {vehid});
	}
	
//	public List<VehicleInfo> getVehicleByCompanyIdNoTeam(int company_id) {
//		String hql = "from VehicleInfo where status=0 and companyid = ? and id not in (select vehicle_id from VehicleTeam where team_id in (select id from Team where company_id = ?))";
//		return find(hql, new Object[]{company_id, company_id});
//	}
	
	public List<Object[]> getVehicleByCompanyIdNoTeam(int company_id) {
		String sql = "select v.id,v.vehid from tb_vehicle v where v.companyid = ? "
				   + "and id not in (select vt.vehicle_id from tb_vehicle_team vt,sys_team t where vt.team_id and t.company_id = ?)";
		//System.out.println("-----getVehicleByCompanyIdNoTeam-----"+sql+"==="+company_id);
		return findSql(sql, new Object[]{company_id,company_id});
	}

	public List<Object[]> getVehicleByTeamId(int team_id) {
		String sql = "select v.id,v.vehid from tb_vehicle v,tb_vehicle_team vt "
				+ "where v.id = vt.vehicle_id and vt.team_id = ?";
		//System.out.println("-----getVehicleByTeamId-----"+sql+"==="+team_id);
		return findSql(sql, new Object[]{team_id});
	}
	
	public List<VehicleInfo> getAllVehicle() {
		String hql = "select devicecode,vehid from VehicleInfo where devicecode is not null";
		return find(hql, new Object[] {});
	}
}
